package pers.cz.javacvdemo.oss.service;

import com.lmax.disruptor.RingBuffer;
import lombok.extern.slf4j.Slf4j;
import pers.cz.javacvdemo.oss.model.EventRecord;
import pers.cz.javacvdemo.oss.model.QueueDataWrapper;

/**
 * @version 1.0
 * @description: 队列生产者
 * @author: ChengZhi 0336
 * @create: 2025-08-14 14:12
 **/
@Slf4j
public class BucketEventProducer {

	private final RingBuffer<QueueDataWrapper> ringBuffer;

	public BucketEventProducer(RingBuffer<QueueDataWrapper> ringBuffer) {
		this.ringBuffer = ringBuffer;
	}
	public void publish(String key, EventRecord eventRecord) {
		long sequence = ringBuffer.next();
		try {
			QueueDataWrapper queueData = ringBuffer.get(sequence);
			queueData.setEventRecord(eventRecord);
			queueData.setKey(key);
		} finally {
			ringBuffer.publish(sequence);
			log.info("发送一条数据到队列！");
		}
	}

}
